package com.qf.util;

import org.quartz.JobDetail;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * 2019/12/6
 * Administrator
 * springboot1206
 * 面向对象面向君  不负代码不负卿
 */
//quartz配置类
@Configuration
public class SpringQuartzTaskConfig {
    //1.任务
    @Bean
    public MethodInvokingJobDetailFactoryBean a1(springQuartzTask task){
        MethodInvokingJobDetailFactoryBean factoryBean = new MethodInvokingJobDetailFactoryBean();
        factoryBean.setTargetObject(task);
        factoryBean.setTargetMethod("myjob");
    return factoryBean;
    }
    //2.触发器
    @Bean
    public CronTriggerFactoryBean b1(MethodInvokingJobDetailFactoryBean fb){
        CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
        factoryBean.setJobDetail(fb.getObject());
        factoryBean.setCronExpression("* * * * * ?");
        return factoryBean;
    }
    //3.调度器
   @Bean
    public SchedulerFactoryBean c1(CronTriggerFactoryBean cronTriggerFactoryBean){
       SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
       factoryBean.setTriggers(cronTriggerFactoryBean.getObject());
       return factoryBean;
   }
}
